package com.qumitech.visualnovel.controller.rest;

import com.qumitech.visualnovel.model.common.BaseRsp;
import com.qumitech.visualnovel.model.common.ResultEnum;
import com.qumitech.visualnovel.service.basic.RegisterChannelBasicStatisticsDataService;
import com.qumitech.visualnovel.service.basic.StartChannelBasicStatisticsDataService;
import com.google.common.collect.ImmutableMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author :  ZhChNing
 * @Descriptiom :
 * @Date Created in 2019/3/12 17:31
 */

@RestController
@RequestMapping("/api/basic")
public class BasicStatisticsController {
    @Autowired
    private RegisterChannelBasicStatisticsDataService registerChannelBasicStatisticsDataService;
    @Autowired
    private StartChannelBasicStatisticsDataService startChannelBasicStatisticsDataService;


    @GetMapping(value = "/statistic/start_channel")
    public BaseRsp getStartChannelBasicStatistics(@RequestParam(value = "offset", defaultValue = "0") Integer offset,
                                                  @RequestParam(value = "limit", defaultValue = "20") Integer limit,
                                                  @RequestParam(value = "app_channel" ,required = false) String appChannel,
                                                  @RequestParam(value = "start_time"  ,required = false) String startTime,
                                                  @RequestParam(value = "end_time" ,required = false) String endTime) {
        return new BaseRsp(ResultEnum.SUCCESS,  ImmutableMap.of("basic_statistics_data",startChannelBasicStatisticsDataService.listBasicStatisticsData(appChannel,startTime,endTime ,offset,limit),
                "count",startChannelBasicStatisticsDataService.getCount(appChannel,startTime,endTime,offset,limit)));
    }

    @GetMapping(value = "/statistic/register_channel")
    public BaseRsp getRegisterChannelBasicStatistics(@RequestParam(value = "offset", defaultValue = "0") Integer offset,
                                                  @RequestParam(value = "limit", defaultValue = "20") Integer limit,
                                                  @RequestParam(value = "app_channel" ,required = false) String appChannel,
                                                  @RequestParam(value = "start_time"  ,required = false) String startTime,
                                                  @RequestParam(value = "end_time" ,required = false) String endTime) {
        return new BaseRsp(ResultEnum.SUCCESS,  ImmutableMap.of("basic_statistics_data",registerChannelBasicStatisticsDataService.listBasicStatisticsData(appChannel,startTime,endTime ,offset,limit),
                "count",registerChannelBasicStatisticsDataService.getCount(appChannel,startTime,endTime,offset,limit)));
    }




}
